#include <GL/glew.h>
#include <GL/freeglut.h>
#include "window.h"

const int PERIOD = 1000 / 60;

int window_width = 1024;
int window_height = 600;

Window * window;

void DisplayFunc()
{
	window->DisplayFunc();
}

void KeyboardFunc(unsigned char c, int x, int y)
{
	window->KeyboardFunc(c, x, y);
}

void MouseFunc(int button, int state, int x, int y)
{
	window->MouseFunc(button, state, x, y);
}

void MotionFunc(int x, int y)
{
	window->MotionFunc(x, y);
}

void ReshapeFunc(int w, int h)
{
	window->ReshapeFunc(w, h);
}

void TimerFunc(int value)
{
	window->TimerFunc(value);
}

int main(int argc, char * argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(window_width, window_height);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
	glutCreateWindow("Still Life");
	
	if (glewInit() != GLEW_OK)
	{
		return 0;
	}

	ilInit();

	window = new Window(window_width, window_height);
	
	// this encapsulates Shader::Initialize()
	if (!window->Initialize())
	{
		return 0;
	}
	
	// set up GL callback functions
	glutDisplayFunc(DisplayFunc); 
	glutKeyboardFunc(KeyboardFunc);
	glutMouseFunc(MouseFunc);
	glutMotionFunc(MotionFunc);
	glutReshapeFunc(ReshapeFunc);
	glutTimerFunc(PERIOD, TimerFunc, 0);

	glutMainLoop();

	return 0;
}